package org.bee.controller;

import jakarta.annotation.Resource;
import org.bee.id.UUIDUtils;
import org.bee.model.queue.NoticeMessage;
import org.bee.secuirty.annotation.TokenIgnore;
import org.bee.sender.NoticeSender;
import org.bee.string.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;


/**
 * 消息发送控制器
 */
@RestController
@RequestMapping("/send")
public class TestSendController {

    private final NoticeSender noticeSender;

    public TestSendController(NoticeSender noticeSender) {
        this.noticeSender = noticeSender;
    }

    /**
     * 发送消息
     * @param msgBody 消息体
     */
    @PostMapping("/sendMsg")
    @TokenIgnore
    public void sendMsg(@RequestBody NoticeMessage msgBody){
        if(StringUtils.isEmpty(msgBody.getMsgId())){
            msgBody.setMsgId(UUIDUtils.simpleUuid());
        }
        msgBody.setSendTime(new Date());
        noticeSender.sendNoticeMessage(msgBody);
    }
}
